import 'package:flutter/material.dart';
import 'package:flutter_getx/app/const.dart';
import 'package:get/get.dart';

import '../controllers/edit_me_controller.dart';

class EditMeView extends GetView<EditMeController> {
  var LabelTextStyle =
      TextStyle(color: Colors.grey, fontWeight: FontWeight.bold);

  Widget InputWithLabel(
      {required String title,
      required String redTitle,
      required TextEditingController controller,
      required TextInputType inputType}) {
    return Container(
      padding: EdgeInsets.only(top: 10, bottom: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text.rich(TextSpan(children: [
            TextSpan(text: title + ":", style: LabelTextStyle),
            TextSpan(
                text: redTitle,
                style:
                    TextStyle(color: Colors.red, fontWeight: FontWeight.bold))
          ])),
          TextField(
            decoration: InputDecoration(
              isCollapsed: true,
              contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 6),
              border: OutlineInputBorder(),
            ),
            keyboardType: inputType,
            controller: controller,
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('编辑个人名片'),
        centerTitle: true,
      ),
      body: Obx(() => Container(
            color: bgColor,
            child: Center(
              child: Card(
                elevation: 20.0,
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(20.0))),
                child: Container(
                  alignment: Alignment.center,
                  width: Get.width * .8,
                  height: Get.height * .7,
                  padding: EdgeInsets.all(20),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Column(
                        children: [
                          Row(
                            children: [
                              Text("性别:", style: LabelTextStyle),
                              Text("男"),
                              Radio(
                                  value: true,
                                  groupValue: controller.gender.value,
                                  onChanged: (e) {
                                    debugPrint(e.toString());
                                    controller.gender.value = true;
                                  }),
                              Text("女"),
                              Radio(
                                  value: false,
                                  groupValue: controller.gender.value,
                                  onChanged: (e) {
                                    controller.gender.value = false;
                                  }),
                            ],
                          ),
                          InputWithLabel(
                              title: "昵称",
                              redTitle: "",
                              controller: controller.nickNameTec,
                              inputType: TextInputType.text),
                          InputWithLabel(
                              title: "个性签名",
                              redTitle: "",
                              controller: controller.introTec,
                              inputType: TextInputType.text),
                          Padding(
                            padding: const EdgeInsets.only(top: 10, bottom: 10),
                            child: GestureDetector(
                              onTap: () {
                                controller.showDateTimePicker();
                              },
                              child: Row(
                                children: [
                                  Text("生日:", style: LabelTextStyle),
                                  Expanded(
                                    child: Container(
                                        padding: EdgeInsets.only(left: 7),
                                        color: Colors.black12,
                                        child: Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Text(controller.birthday.value,
                                                style: TextStyle(fontSize: 18)),
                                            Icon(Icons.arrow_right)
                                          ],
                                        )),
                                  )
                                ],
                              ),
                            ),
                          )
                        ],
                      ),
                      ElevatedButton(onPressed: () {
                        controller.updateInfo();
                        Get.back();
                      }, child: Text("提交"))
                    ],
                  ),
                ),
              ),
            ),
          )),
    );
  }
}
